<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;

class Comments extends Controller
{

    public function index()
    {
        $comments = Db::name("comments c")
        ->join("goods g","c.goodId=g.gId")->join("user u","c.uId=u.userId")
        ->where("cstatus",0)
        ->field("cId,cContent,gId,gTitle,name")
        ->select();
        // dump($comments);
        $this->assign("comments",$comments);
        return $this->fetch();
    }

    public function dellot($key){
        $data = [
            "cstatus"=>1
        ];
        $rs = Db::name("comments")
        ->whereLike("cContent","%".$key."%")
        ->update($data);
        echo Db::name("comments")->getLastSql();
    }

    public function del($cid)
    {
        // $data = [
        //     "cId"=>$id,
        //     "cstatus"=>1
        // ];
        // $rs = Db::name("comments")->update($data);
        // if($rs){
        //     $this->redirect('index');
        // }else{
        //     $this->redirect('index?err=1');
        // }

        if (Db::name('comments')->delete($cid)) {
            $this->success('删除成功', 'index');
        } else {
            $this->error('删除失败', 'index');
        }
    }



    public function forbidden(){
        $comments = Db::name("comments c")
        ->join("goods g","c.goodId=g.gId")->join("user u","c.uId=u.userId")
        ->where("cstatus",1)
        ->field("cId,cContent,gId,gTitle,name")
        ->select();
        $this->assign("comments",$comments);
        return $this->fetch();
    }
    public function recoverlot($key){
        $data = [
            "cstatus"=>0
        ];
        $rs = Db::name("comments")
        ->whereLike("cContent","%".$key."%")
        ->update($data);
        echo Db::name("comments")->getLastSql();
    }

}
